//go:build windows

package gbase

import (
	"os/exec"
	"strconv"
	"strings"
	"syscall"
)

// IsPortInUse 检查端口是否被占用（Windows 版本）
func IsPortInUse(port int) bool {
	cmd := exec.Command("netstat", "-ano")
	cmd.SysProcAttr = &syscall.SysProcAttr{
		HideWindow:    true,
		CreationFlags: 0x08000000, // CREATE_NO_WINDOW
	}
	output, err := cmd.Output()
	if err != nil {
		return false
	}

	list := strings.SplitSeq(string(output), "\n")
	for v := range list {
		if strings.Contains(v, strconv.Itoa(port)) && strings.Contains(v, "LISTENING") {
			return true
		}
	}
	return false
}
